<template>
	<view>
		<view class="fixed-top bg-white">
			<view class="mt-3 pr-3 text-right">
				<u-button @click="open('tabbar/user/credit')" size="mini"
					style="background-color: #8ED0F2; color: #fff;">
					积分任务
				</u-button>
			</view>
			<view class="text-center lineHight-2 pb-4">
				<view class="font-24 font-weight-bold text-FFC251">{{notices}}</view>
				<view class="font-14">我的积分</view>
			</view>
			<view style="height: 40px; background-color:#EFEDE9;">
				<view class="pl-2 font-14 lineHight-40">积分明细</view>
			</view>
		</view>
		<view style="margin-top: 200px;">
			<scroll-view ref="scrollView" scroll-y scroll-with-animation style="height: calc(100vh - 0px);"
				:show-scrollbar="false" @scrolltolower="loadMore" @pulldownrefresh="refresh">
				<view v-for="(item, index) in brandPointsList" :key="index"
					class="dfex pl-2 pr-2 py-1 mt-2 border-E0E3EA">
					<view class="lineHight-2">
						<view v-if="item.type === '1'" class="text-101010 font-16">基本信息</view>
						<view v-if="item.type === '2'" class="text-101010 font-16">基地信息</view>
						<view v-if="item.type === '3'" class="text-101010 font-16">产品信息</view>
						<view v-if="item.type === '4'" class="text-101010 font-16">个人标签</view>
						<view v-if="item.type === '5'" class="text-101010 font-16">上下游商城</view>
						<view v-if="item.type === '6'" class="text-101010 font-16">上市简报信息</view>
						<view v-if="item.type === '7'" class="text-101010 font-16">上市预报信息</view>
						<view v-if="item.type === '8'" class="text-101010 font-16">每日签到</view>
						<view class="font-12 text-A0A0A0">{{item.createTime}}</view>
					</view>
					<view class="font-weight-bold font-16 text-FFC251">+{{item.value}}</view>
				</view>
				<view v-if="!hasMore && brandPointsList.length > 0" class="text-center mt-3 mb-3">
					<view class="text-muted">没有更多数据了</view>
				</view>
				<view v-else-if="!hasMore && brandPointsList.length === 0" class="text-center mt-3 mb-3">
					<view class="iconfont text-999999 icon-zanwushuju font-48 pb-1"></view>
					<view class="text-999999 font-15">暂无数据</view>
				</view>
				<view v-else class="text-center mt-3 mb-3">
					<view class="btn btn-primary">加载更多</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>


<script>
	import $H from '@/common/free-lib/request.js';

	export default {
		data() {
			return {
				notices: {},
				brandPointsList: [],
				form: {
					pageNo: 1,
					pageSize: 10,
					total: 0 // 总页数
				},
				hasMore: true // 是否还有更多数据
			}
		},
		onShow() {
			this.NewDataList();
		},
		onLoad() {
			this.brandPoints();
		},
		methods: {
			// 获取我的数据
			NewDataList() {
				$H.get('/basisInform/integral/agriculture/integralSignInTotal', {}, {})
					.then(res => {
						this.notices = res.result;
					})
					.catch(error => {
						uni.showToast({
							title: "网络错误，请稍后再试",
							icon: 'none'
						});
					});
			},
			// 获取积分明细
			brandPoints() {
				$H.get('/basisInform/integral/agriculture/queryIntegralDetailsList', {
						...this.form
					}, {})
					.then(res => {
						if (this.form.pageNo === 1) {
							this.brandPointsList = res.result.records; // 首次加载或刷新时，直接覆盖数据
						} else {
							this.brandPointsList = [...this.brandPointsList, ...res.result.records]; // 加载更多时，拼接数据
						}
						this.form.total = res.result.total;
						this.hasMore = this.form.pageNo * this.form.pageSize < this.form.total;
					})
					.catch(error => {
						uni.showToast({
							title: "网络错误，请稍后再试",
							icon: 'none'
						});
					});
			},
			// 加载更多
			loadMore() {
				if (this.hasMore) {
					this.form.pageNo++;
					this.brandPoints();
				}
			},
			// 下拉刷新
			refresh() {
				this.form.pageNo = 1;
				this.brandPointsList = [];
				this.hasMore = true;
				this.brandPoints();
				// 结束下拉刷新动画
				setTimeout(() => {
					uni.stopPullDownRefresh();
				}, 1000);
			},
			open(path) {
				uni.navigateTo({
					url: '/pages/' + path
				});
			}
		}
	}
</script>

<style>
</style>